package top.igotcha.chapter.chapter7.ThreadPoolExecutor01;

import java.util.concurrent.TimeUnit;

/**
 * @author Gotcha
 * @date 2021/3/11
 * @describe
 */
public class ThreadPool01Test {
    public static void main(String[] args) {
        ThreadPool01 threadPool = new ThreadPool01(1, 1000, TimeUnit.MILLISECONDS,
                1,(queue,task)->{
            //1.死等
            //queue.put(task);
            //2.带超时的等待
            //queue.put(task,500,TimeUnit.MILLISECONDS);
            //3.让调用者放弃任务执行
            //System.out.println("放弃执行" + task);;
            //4.让调用者抛出异常
            //throw new RuntimeException("任务执行失败" + task);
            //5.让调用者自己执行任务
            task.run();
        });
        for (int i = 0; i < 4; i++) {
            int j = i;
            threadPool.execute(()-> {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(j);});
        }
    }
}
